【论文笔记】RTFM! Automatic Assumption Discovery and Verification Derivation from Library Document for API Misuse Detection

2020-11-03-Advance

会议:CCS’20

论文名称:RTFM! Automatic Assumption Discovery and Verification Derivation from Library Document for API Misuse Detection

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled.png


Keywords

API misuse; Integration assumption; Verification code generation; Documentation analysis; NLP

Introduction

软件开发过程中会大量使用到其他程序组件中的API,这些API的使用可能存在一定的条件约束,比如传入参数的长度、返回值的范围、调用的上下文等。这些约束条件(Integration Assumptions ,IAs)通常以文档的形式记录下来。而软件开发者可能在开发过程中没有注意到这些API的约束条件,违反了这些约束条件,从而导致了API的误用(misuse)。

之前针对API misuse的检测依赖于通过分析一系列的代码以推测出API的约束条件,然而这样推断出的IAs通常缺乏精度,带来大量的false positives。

因此,作者希望通过自动化的从API文档中提取出约束条件,从而利用程序分析检测出使用了这些API的代码中存在的误用。

Motivating Example:

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%201.png

其中难点在于如何从结构松散的描述文档中抽象出能够用于程序分析的约束表达式。作者的方案是利用机器学习和NLP,通过sentiment analysis(”must”, “should”, “”)发现API的约束,通过词法分析、语义分析来发现implicit references(“it”)。

作者设计出了Advance (assumption discovery and verification derivation from the document)的原型系统,利用NLP对文档进行分析,提取出其中的约束条件并转换为参数验证代码,以进行API misuse的检测。

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%202.png

IA Discovery:在文档中提取出IAs,比如SQLite中的“the application must finalize every prepared statement”,libpcap中的“make sure that you explicitly check for PCAP_ERROR”。为此,作者设计了一个基于语义的分类器,Sentence Hierarchical Attention Network(S-HAN),使用OpenSSL人工标记进行训练,最后准确率达到88%,优于其他模型(Text-CNN and RCNN)。

IA Dereference:解析IA,将文字描述中的“指代”进行翻译,对应到具体的函数/参数。如Figure 3中所示。

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%203.png

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%204.png

Verification Code Generation:提取出Code description(如“data must”),并转换为verification code snippets (VCSes),如“the length of argv”将被转为array_length(argv)。随后利用IA Dereference的结果构造出完整的Verification code。如下图中构造出array_length(EVP_param_2)% 4 = 0。

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%205.png

Evaluation

作者使用Advance对5个库和39个应用程序进行分析,一共发现了193个API misuses,其中139个为之前没有报出过的。

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%206.png

2020-11-03-Advance%202454d5bacc684a0982f309312c0f045a/Untitled%207.png

Effectiveness of IA discovery:使用在OpenSSL中通过人工标记训练出的模型,在OpenSSL, SQLite, libpcap, libdbus, libxml2 中进行IA discovery,最终准确率为88%(Table 2中所示)。

Effectiveness of IA dereference:提取API和Parameter的准确率分别为94%和89%

Effectiveness of VC generation:召回率为69%

Conclusion

作者利用机器学习和NLP来抽象API文档中的约束条件,并发现了较多的API misuse。方式新颖,效果也很好,是NLP与API应用安全结合的一大创新。如果文档形式能更为规范,则能够更加准确的对API约束条件建模,进一步提高API误用的检出率。